package com.youku.plugins.toolboxV4.view
{
   import flash.display.Sprite;
   import com.youku.interfaces.ISkinChangeCompent;
   import com.youku.baseUI.YoukuTextField;
   import com.youku.baseUI.BasePlayerButton;
   import com.youku.utils.AssetUtil;
   import flash.display.MovieClip;
   import com.youku.plugins.toolboxV4.ToolboxFont;
   import flash.text.TextFieldAutoSize;
   import com.youku.plugins.toolboxV4.ToolboxConstant;
   import com.youku.skin.PartenerSkinManager;
   import flash.events.MouseEvent;
   import com.youku.plugins.toolboxV4.ToolboxEvent;
   import com.youku.utils.ReportUtil;
   import com.youku.interfaces.IDVDData;
   import com.youku.plugins.toolboxV4.model.ToolboxData;
   import com.youku.PlayerConfig;
   import flash.text.TextFormat;
   import com.youku.skin.YaheiFontManager;
   
   public class Toolbox extends Sprite implements ISkinChangeCompent
   {
      
      public function Toolbox() {
         super();
         this.init();
      }
      
      protected var _background:Sprite;
      
      protected var _title:YoukuTextField;
      
      protected var _closeButton:BasePlayerButton;
      
      protected var _defaultQualityPanel:DefaultQualityPanel;
      
      protected var _qualityPanel:QualityPanel;
      
      protected var _headPanel:HeadPanel;
      
      protected var _continuousPanel:ContinuousPanel;
      
      protected var _dvdPanel:DvdPanel;
      
      protected var _confirmButton:BasePlayerButton;
      
      protected var _cancleButton:BasePlayerButton;
      
      protected var _width:Number;
      
      protected var _height:Number;
      
      private function init() : void {
         this._background = AssetUtil.getAsset("V4_panel_bg") as MovieClip;
         this._background.width = 330;
         this._background.height = 230;
         this._title = AssetUtil.getYoukuTextField(false);
         this._title.defaultTextFormat = ToolboxFont.FONT_SET;
         this._title.autoSize = TextFieldAutoSize.LEFT;
         this._title.text = "设置";
         this._closeButton = AssetUtil.getStyleButton("P_CloseButton");
         AssetUtil.restoreButtonSize(this._closeButton);
         this._defaultQualityPanel = new DefaultQualityPanel();
         this._qualityPanel = new QualityPanel();
         this._headPanel = new HeadPanel();
         this._continuousPanel = new ContinuousPanel();
         this._dvdPanel = new DvdPanel();
         this._confirmButton = AssetUtil.getStyleButton("P_Button_OK");
         this._confirmButton.hardOffset = -3;
         this._confirmButton.setStyle("textFormat",ToolboxFont.FONT_BUTTON_CONFIRM);
         this._confirmButton.label = "确定";
         this._confirmButton.setSize(80,30);
         this._cancleButton = AssetUtil.getStyleButton("P_Button_Cancel");
         this._cancleButton.hardOffset = -3;
         this._cancleButton.setStyle("textFormat",ToolboxFont.FONT_BUTTON_CANCLE);
         this._cancleButton.label = "取消";
         this._cancleButton.setSize(80,30);
         addChild(this._background);
         addChild(this._title);
         addChild(this._closeButton);
         addChild(this._defaultQualityPanel);
         addChild(this._qualityPanel);
         addChild(this._headPanel);
         addChild(this._continuousPanel);
         addChild(this._dvdPanel);
         addChild(this._confirmButton);
         addChild(this._cancleButton);
         this.attchEvents();
         this.setSize(ToolboxConstant.TOOLBOX_WIDTH,ToolboxConstant.TOOLBOX_HEIGHT);
         PartenerSkinManager.push(this);
      }
      
      public function reset() : void {
      }
      
      private function attchEvents() : void {
         this._closeButton.addEventListener(MouseEvent.CLICK,this.onCloseButtonClick);
         this._cancleButton.addEventListener(MouseEvent.CLICK,this.onCancleButtonClick);
         this._confirmButton.addEventListener(MouseEvent.CLICK,this.onConformButtonClick);
         this._qualityPanel.addEventListener(ToolboxEvent.QUALITY_1080P_CLICK,this.onPanelEvent);
         this._defaultQualityPanel.addEventListener(ToolboxEvent.QUALITY_1080P_CLICK,this.onPanelEvent);
      }
      
      private function onPanelEvent(param1:ToolboxEvent) : void {
         dispatchEvent(new ToolboxEvent(param1.type,param1.data));
      }
      
      private function onConformButtonClick(param1:MouseEvent) : void {
         ReportUtil.sendUserActionLog(ReportUtil.SETTINGS_PANEL_CONFIRM);
         dispatchEvent(new ToolboxEvent(ToolboxEvent.CONFIRM_BUTTON_CLICK));
      }
      
      private function onCancleButtonClick(param1:MouseEvent) : void {
         ReportUtil.sendUserActionLog(ReportUtil.SETTINGS_PANEL_CANCEL);
         dispatchEvent(new ToolboxEvent(ToolboxEvent.CANCLE_BUTTON_CLICK));
      }
      
      private function onCloseButtonClick(param1:MouseEvent) : void {
         ReportUtil.sendUserActionLog(ReportUtil.SETTINGS_PANEL_CLOSE);
         dispatchEvent(new ToolboxEvent(ToolboxEvent.CLOSE_BUTTON_CLICK));
      }
      
      public function setSize(param1:Number, param2:Number) : void {
         this._width = param1;
         this._height = param2;
         if(this.contains(this._background))
         {
            removeChild(this._background);
         }
         this._background.width = this._width;
         this._background.height = this._height;
         addChildAt(this._background,0);
         this.updateLayout();
      }
      
      private function updateLayout() : void {
         this._background.x = this._background.y = 0;
         this._title.x = 11;
         this._title.y = 11;
         this._closeButton.x = this._background.x + this._background.width - this._closeButton.width - 10;
         this._closeButton.y = 10;
         this._defaultQualityPanel.x = 0;
         this._defaultQualityPanel.y = 34;
         this._qualityPanel.x = 0;
         this._qualityPanel.y = 62;
         this._headPanel.x = 0;
         this._headPanel.y = 90;
         this._continuousPanel.x = 0;
         this._continuousPanel.y = 118;
         this._dvdPanel.x = 0;
         this._dvdPanel.y = 146;
         var _loc1_:Number = this._confirmButton.width + 36 + this._cancleButton.width;
         this._confirmButton.x = this._background.x + (this._background.width - _loc1_) / 2;
         this._confirmButton.y = 184;
         this._cancleButton.x = this._confirmButton.x + this._confirmButton.width + 30;
         this._cancleButton.y = this._confirmButton.y;
      }
      
      public function showPanel() : void {
         this._confirmButton.visible = true;
         this.updateLayout();
      }
      
      override public function get width() : Number {
         return this._background.width;
      }
      
      override public function get height() : Number {
         return this._background.height;
      }
      
      public function setFunctionValues(param1:Boolean, param2:Boolean) : void {
         this._continuousPanel.setIsContinuous(param1);
         this._headPanel.setJump(param2);
      }
      
      public function setQualities(param1:Array) : void {
         this._qualityPanel.setQualities(param1);
      }
      
      public function setDefaultQuality(param1:String) : void {
         this._defaultQualityPanel.setDefaultQuality(param1);
      }
      
      public function selectQuality(param1:String) : void {
         this._qualityPanel.selectQuality(param1);
      }
      
      public function setVoice(param1:String) : void {
         this._dvdPanel.setVoice(param1);
      }
      
      public function setDVDValues(param1:IDVDData) : void {
         this._dvdPanel.setData(param1);
      }
      
      public function getCurrentData() : ToolboxData {
         var _loc1_:ToolboxData = new ToolboxData();
         _loc1_.defaultQuality = this._defaultQualityPanel.getDefaultQuality();
         _loc1_.quality = this._qualityPanel.getQuality();
         _loc1_.isContinuous = this._continuousPanel.getIsContinuous();
         _loc1_.isJump = this._headPanel.getIsJump();
         _loc1_.voice = this._dvdPanel.getVoice();
         return _loc1_;
      }
      
      public function upDateSkin() : void {
         if(PlayerConfig.rootData.styleid < 2)
         {
            return;
         }
         if(PlayerConfig.partnerData.skinData.status == 0 || !PlayerConfig.partnerData.skinData.isSetupDiv)
         {
            return;
         }
         this._confirmButton.setStyle("textFormat",new TextFormat(YaheiFontManager.MICROSOFT_YAHEI,14,PlayerConfig.partnerData.skinData.setup_txt));
         this._confirmButton.invalidate();
         this._confirmButton.getStyle("upSkin").filters = PartenerSkinManager.getFilters(PartenerSkinManager.SETUP_BTN);
         this._confirmButton.getStyle("overSkin").filters = PartenerSkinManager.getFilters(PartenerSkinManager.SETUP_BTN,true);
         this._confirmButton.getStyle("downSkin").filters = PartenerSkinManager.getFilters(PartenerSkinManager.SETUP_BTN,true);
      }
      
      public function clearSkin() : void {
         this._confirmButton.setStyle("textFormat",ToolboxFont.FONT_BUTTON_CONFIRM);
         this._confirmButton.invalidate();
         this._confirmButton.getStyle("upSkin").filters = [];
         this._confirmButton.getStyle("overSkin").filters = [];
         this._confirmButton.getStyle("downSkin").filters = [];
      }
   }
}
